// tslint:disable-next-line:ordered-imports
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import hide from '@dfeidao/atom-web/ui/hide';
import show from '@dfeidao/atom-web/ui/show';
import p001 from './p001';
import p002 from './p002';
import p003 from './p003';

export default async function a001(fd: IFeidaoAiBrowserComponent, equip_depart: string, project: string,
	assetsname: string, asset_classification: string, timeout_alert: number, customer_assets: number) {
	// 获取对象
	const dt1 = fd.data.node.querySelector<HTMLElement>('[data-feidao-presentation="p001"]');
	const dt2 = fd.data.node.querySelector<HTMLElement>('[data-feidao-presentation="p002"]');
	const dt3 = fd.data.node.querySelector<HTMLElement>('[data-feidao-presentation="p003"]');
	// 将传入的值储存
	set(fd, 'equip_depart', equip_depart);
	set(fd, 'project', project);
	set(fd, 'asset_classification', asset_classification);
	set(fd, 'assetsname', assetsname);
	set(fd, 'timeout_alert', timeout_alert);
	set(fd, 'customer_assets', customer_assets);
	// 获取储存的值
	const type = get(fd, 'type');
	let pn = get(fd, 'pn');// 获取当前页码
	if (pn === undefined) {
		pn = 1;
	}
	let name = get(fd, 'name');
	if (name === undefined) {
		name = "maintenance_time";
	}
	const data = {
		responsible_no: "YG00000077",
		equip_depart,
		project,
		assetsname,
		asset_classification,
		timeout_alert,
		customer_assets,
		type,
		name,
		pn
	};
	// 获取搜索的数据
	if (type === "0") {
		// 获取排序后的数据
		const res = await nodejs<{ dt: Array<{}>; coun: number }>(
			'project-assets/zj-000002/s001', {
				filter: data
			});
		if (res.dt.length > 0) {
			render(fd, res.dt, p001, 'p001', 'inner');
			if (res.coun > 20) {
				render(fd, res.coun, p003, 'p003', 'inner');
				show(dt3);
			} else {
				hide(dt3);
			}
			show(dt1);
			hide(dt2);
		} else {
			render(fd, "", p002, 'p002', 'inner');
			hide(dt1);
			hide(dt3);
			show(dt2);
		}
	} else {
		// 获取排序后的数据
		const res = await nodejs<{ dt: Array<{}>; coun: number }>(
			'project-assets/zj-000002/s001', {
				filter: data
			});
		if (res.dt.length > 0) {
			render(fd, res.dt, p001, 'p001', 'inner');
			if (res.coun > 20) {
				render(fd, res.coun, p003, 'p003', 'inner');
				show(dt3);
			} else {
				hide(dt3);
			}
			show(dt1);
			hide(dt2);
		} else {
			render(fd, "", p002, 'p002', 'inner');
			hide(dt1);
			hide(dt3);
			show(dt2);
		}
	}


}
